<!DOCTYPE html>
<html lang="ru">
<head>
	<meta charset="utf-8">
	<title>Goldentime</title>
	<link href='http://fonts.googleapis.com/css?family=PT+Sans+Narrow&subset=cyrillic,latin' rel='stylesheet' type='text/css'>
	<link rel="stylesheet" href="../template/style.css" type="text/css" media="screen" />
	<?php include'../library/core.php';
		$gamers_obj = new gamers();
		$users_obj = new users();
		$admin_obj = new admin();
		include'../library/class.location.php'; 
	?>
	<script type="text/javascript">var HTTP_HOST = '<?php echo HTTP_HOST; ?>';</script>
	<script type="text/javascript" src="../template/js/jquery.js"></script>
	<script type="text/javascript" src="../template/js/core.js"></script>	
	<script type="text/javascript" src="../template/js/location.js"></script>
	<script type="text/javascript" src="../template/js/ajaxupload.js"></script>
	<script type="text/javascript" src="../template/js/script.js"></script>
	<script type="text/javascript" src="../template/js/jquery.Jcrop.js"></script>
	<script type="text/javascript" src="../template/js/tiny_mce/jquery.tinymce.js"></script>

	<script type="text/javascript">
		$(document).ready(function(){
			$('textarea.tinymce').tinymce({
				script_url : '../template/js/tiny_mce/tiny_mce.js',
				theme : "advanced",
				plugins : "autoresize,autolink,lists,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,advlist",
				theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect,|,code",
				theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview",
				theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,advhr,|,ltr,rtl,|,fullscreen",
				theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,|,forecolor,backcolor",
				theme_advanced_toolbar_location : "top",
				theme_advanced_toolbar_align : "left",
				theme_advanced_statusbar_location : "bottom",
				theme_advanced_resizing : false,
				mode : "textareas",
				content_css : "../template/css/tinymce.css",
				template_external_list_url : "lists/template_list.js",
				external_link_list_url : "lists/link_list.js",
				external_image_list_url : "lists/image_list.js",
				media_external_list_url : "lists/media_list.js", 
				template_replace_values : {
					username : "Some User",
					staffid : "991234"
				}
			});
			 			
		});
		jQuery(function($){
			$('#cropbox').Jcrop();
		});
	</script>
	 <script>  
             
        
    </script>  
</head>
<body>
<header>
	<div class="menu_bg">
		<div class="logo">
			<a href="../index.php" title="Goldentime"><img src="../images/header/logo.png" alt="Goldentime"/></a>
		</div>
		<nav>
			<ul>
				<?php
					$mas = $admin_obj->in_menu();
					if ($mas!=false){
						for ($i=0; $i<count($mas);$i++){
							echo '<li><a href="../page.php?idpage='.$mas[$i]['id'].'" title="'.$mas[$i]['title'].'">'.$mas[$i]['title'].'</a></li>';
						}
					}
				?>
			</ul>
		</nav>
	</div>
</header>
	<?php
		if ((isset($_SESSION['user']['id']))&&(!empty($_SESSION['user']))){
			$about_user = $users_obj->dataUser($_SESSION['user']['id']);
			$_SESSION['user']['question'] = 1;
			$users_obj->update_question($_SESSION['user']['id']);
			if ($about_user['question'] == 0){
				echo '<div class="fog"></div>';
			}
		}	
		if (isset($_GET['action']) && ($_GET['action']=='exit')){
			if (!empty($_SESSION['user'])){
				$core_obj->no_active($_SESSION['user']['id']);
				$core_obj->last_visited($_SESSION['user']['id']);
				$_SESSION['user'] = array();
			}
		}
		if (!isset($_SESSION['user']['id'])):?>	
			<script type="text/javascript"> window.location.href = '../index.php'</script>				
		<?php endif; ?>
	<section class="inside">
		<div class="content">
			<div class="main-wrap">
				<?php if (isset($_GET['action']) && ($_GET['action']=='pyramid') ):?>
				<h3 class="page_title">Моё дерево</h3>
				<div class="hr"></div>
				<?php
					$f2 = true;
					$f3 = true;				
					$mas_1 = $admin_obj->mas_1($_SESSION['user']['id']);
					
					if (isset($mas_1)){
						$mas_2 = $admin_obj->mas_2($mas_1);
						for($i = 0; $i < count($mas_2); $i++)
						$n = count($mas_2);						 
						 for($i = 0; $i < $n; $i++){
							if( (isset($_GET['gamer_id'])) && ($_GET['gamer_id'] == $mas_2[$i])){
								$f2 = false;
								break;
							}
						}
					}
					if (isset($mas_2)){
						$mas_3 = $admin_obj->mas_2($mas_2);
						$n = count($mas_3);			
							for($i = 0; $i < $n; $i++){					
							  if( (isset($_GET['gamer_id'])) && ($_GET['gamer_id'] == $mas_3[$i])){				  
								$f3 = false;
								break;
							}
						}
					}
					$about_gamer = $gamers_obj->about_gamer($_SESSION['user']['id']);
					$layer = $about_gamer['layer'];
					$gamers_obj->next_parent($_SESSION['user']['id'],$layer);
					$permit = false;
							
					if ($layer == 1){
						$counter = count($mas_1);
						if ($counter == 3)
							$permit = true;
						for ($i = 0; $i < 3; $i++){
							if (isset($mas_1[$i]) && ($mas_1[$i]!=null))
								echo '<div class="green"></div>';
							if (!isset($mas_1[$i]) || ($mas_1[$i]==null))
								echo '<div class="red"></div>';					
						}
					}
					
					if ($layer == 2){
						$counter = count($mas_2);

						if ($counter == 9)
							$permit = true;
						for ($i = 0; $i < 9; $i++){
							if (isset($mas_2[$i]) && ($mas_2[$i]!=null))
								echo '<div class="green"></div>';
							if (!isset($mas_2[$i]) || ($mas_2[$i]==null))
								echo '<div class="red"></div>';					
						}
					}
					
					if ($layer == 3){
						$counter = count($mas_3);
						if ($counter == 27)
							$permit = true;
						for ($i = 0; $i < 27; $i++){
							if (isset($mas_2[$i]) && ($mas_2[$i]!=null))
								echo '<div class="green"></div>';
							if (!isset($mas_2[$i]) || ($mas_2[$i]==null))
								echo '<div class="red"></div>';					
						}
					}
					if ($about_user['privilege'] == 3)
						echo '<form action="" method="post" class="fpyramid">
									<p>
										<input type="text" name="find_pyramid" id="find_pyramid" placeholder="Поиск по Идентификатору" class="find"  maxlength="255"/>
										<input type="submit" value=""/>
									</p>
							  </form>
							  <div class="hr"></div>';
					
					$money_layer = $gamers_obj->money_layer($layer+1);

					$payd_amount = 0;
					if ($about_gamer['layer'] == 1)
						$payd_amount = 3*LAYER1;
					if ($about_gamer['layer'] == 2)
						$payd_amount = 3*LAYER1+9*LAYER2;
					if ($about_gamer['payd'] == 1)
						$passed = 'Пройдено';
					else
						$passed = 'Не пройдено';
					if (($about_user['privilege']!=3) && ($about_user['status']!=0)){
						echo '<h3 class="page_title">Вы сейчас на уровне '.$about_gamer['layer'].' ( '.$passed.' )</h3>';
					if ($about_gamer['amount_paid'])
						echo '<h3 class="page_title">Ваш куратор id='.$about_gamer['next_parent'].'</h3>';
						
						//$next_id = $gamers_obj->next_parent($_SESSION['user']['id'],$layer);
						$res = $users_obj->dataUser($about_gamer['next_parent']);
						$parent_payd = $gamers_obj->is_payd($about_gamer['next_parent']);
						$res_parent = $gamers_obj->dataGamer($about_gamer['next_parent']);
					}
					if (!empty($res))
					
					//if ((($about_user['privilege']!=3)&& ($permit) && ($about_gamer['wait_money'] == 0) && ($about_gamer['payd']!=0) && ($about_gamer['amount_paid'] == $payd_amount)) ||(($about_gamer['payd']==0) && ($parent_payd['payd'] == 1)) && ($about_gamer['wait_money']==0)):
					if ((($parent_payd == 1) && ($about_gamer['payd'] == 0)) && ($about_gamer['wait_money'] == 0) && ($res_parent['layer']>=$about_gamer['layer'])):?>
				
		
					<div class="payment">
							<span><p>Ваш следующий Куратор: </p></span>	
							<table class="next_parent">
								<tr class="light">
									<td>Идентификатор</td>
									<td><?php echo $res['id']; ?></td>
								</tr>
								<tr class="dark">
									<td>Логин</td>
									<td><?php echo $res['login']; ?></td>									
								</tr>
								<tr class="light">
									<td>ФИО</td>
									<td><?php echo $res['name'].' '.$res['surname']; ?></td>
								</tr>
								<tr class="dark">
									<td>Номер телефона</td>
									<td><?php echo $res['phone']; ?></td>									
								</tr>
								<tr class="light">
									<td>email</td>
									<td><?php echo $res['email']; ?></td>
								</tr>
								<tr class="dark">
									<td>Место проживания</td>
									<td><?php echo  $core_obj->value_country($res['country'],$res['country']); ?>, <?php echo $core_obj->value_city_show($res['city']); ?></td>									
								</tr>
							</table>
							<form action="" method="post" class="about_user">
								<p><input type="button" value="Пройти уровень <?php echo $about_gamer['layer']; ?>" id="money"/>
								<input type="button" value="Жалоба Администратору" id="complain_curator"/></p>	
							</form>
					</div>
					
				<?php 
					endif; ?>			
				<div class="pyramid">		
				<?php 				
				if ($about_user['privilege']!=3){
					if ($about_user['status']!=0){
						if (!isset($_GET['gamer_id']))
							$identuficator = $_SESSION['user']['id'];
						else
							$identuficator = $_GET['gamer_id'];		
						{
						$top = false;			
							if (isset($mas_1))
								for ($i=0;$i<count($mas_1);$i++){
									if ($identuficator == $mas_1[$i]){						
										$top = true;
										break;	
									}
								}
							if (($top == false) && ((isset($mas_2))))
								for ($i=0;$i<count($mas_2);$i++){
									if ($identuficator == $mas_2[$i]){
										$top = true;
										break;	
									}
								}
							if (($top == false) && ((isset($mas_3))))
								for ($i=0;$i<count($mas_3);$i++){
									if ($identuficator == $mas_3[$i]){
										$top = true;
										break;
									}
								}
							
							if ($top == false){
								$identuficator = $_SESSION['user']['id'];
								$_GET['gamer_id'] = $identuficator;
							}
						}
						
						$mas_minus_1 = $gamers_obj->minus_level($identuficator);
						if (isset($mas_minus_1)){
							$mas_minus_2 = $gamers_obj->minus_level($mas_minus_1);
						}
						if (isset($mas_minus_2)){
							$mas_minus_3 = $gamers_obj->minus_level($mas_minus_2);						
						}
						
						if (isset($mas_minus_3) && ($mas_minus_3 != 0))
							$gamers_obj->minus($mas_minus_3, $about_user['privilege'],$_SESSION['user']['id']);
						if (isset($mas_minus_2) && ($mas_minus_2 != 0))
							$gamers_obj->minus($mas_minus_2, $about_user['privilege'],$_SESSION['user']['id']);
						if (isset($mas_minus_1) && ($mas_minus_1 != 0))
							$gamers_obj->minus($mas_minus_1, $about_user['privilege'],$_SESSION['user']['id']);
						
						$gamers_obj->zero($identuficator,$about_user['privilege'],$_SESSION['user']['id']);
						
						if ($f3){
							echo '<div class="two">';
							$first_level_mas = $gamers_obj->child($identuficator);
							for ($i=0;$i<3;$i++){
								if (isset($first_level_mas[$i]))
									$gamers_obj->first_level($first_level_mas[$i],$about_user['privilege'],$_SESSION['user']['id']);
								else{
									if (!isset($_GET['gamer_id']))
										$_GET['gamer_id'] = $_SESSION['user']['id'];
										$gamers_obj->free_first_level($_SESSION['user']['id'],$_GET['gamer_id'],$about_user['privilege']);
									}
								}
							echo '</div>';
							}
								
						$j = 0;
						if (($f3) && ($f2)){
							while ($j != 3)
							{
								if (isset($first_level_mas[$j])){
									echo '<div class="three">';
									$second_level_mas = $gamers_obj->child($first_level_mas[$j]);
									for ($i=0;$i<3;$i++){
										if (isset($second_level_mas[$i]))
											$gamers_obj->second_level($second_level_mas[$i],$about_user['privilege']);
										else
										{
											if (isset($first_level_mas[$j]))
												$gamers_obj->free_second_level($_SESSION['user']['id'],$first_level_mas[$j],$about_user['privilege']);
										}
									}
									echo '</div>';
								}
								
								$j++;
							}	
						}
					}
					} else {
						
					if (!isset($_GET['gamer_id']))
						$identuficator = $_SESSION['user']['id'];
					else
						$identuficator = $_GET['gamer_id'];	
						
					if (isset($_POST['find_pyramid']) && ($gamers_obj->is_gamer((int)$_POST['find_pyramid'])))
						$identuficator = (int)$_POST['find_pyramid'];
					if ($identuficator == 0)
						$identuficator = $_SESSION['user']['id'];
						
						$mas_minus_1 = $gamers_obj->minus_level($identuficator);
						if (isset($mas_minus_1)){
							$mas_minus_2 = $gamers_obj->minus_level($mas_minus_1);
						}
						if (isset($mas_minus_2)){
							$mas_minus_3 = $gamers_obj->minus_level($mas_minus_2);						
						}
						if (isset($mas_minus_3) && ($mas_minus_3 != 0))
							$gamers_obj->minus($mas_minus_3, $about_user['privilege'],$_SESSION['user']['id']);
						if (isset($mas_minus_2) && ($mas_minus_2 != 0))
							$gamers_obj->minus($mas_minus_2, $about_user['privilege'],$_SESSION['user']['id']);
						if (isset($mas_minus_1) && ($mas_minus_1 != 0))
							$gamers_obj->minus($mas_minus_1, $about_user['privilege'],$_SESSION['user']['id']);
						
						
						
					$gamers_obj->zero($identuficator,$about_user['privilege'],$_SESSION['user']['id']);
			
					echo '<div class="two">';
					$first_level_mas = $gamers_obj->child($identuficator);
					for ($i=0;$i<3;$i++){
						if (isset($first_level_mas[$i]))
							$gamers_obj->first_level($first_level_mas[$i],$about_user['privilege'],$_SESSION['user']['id']);
						else{
							if (!isset($_GET['gamer_id']))
								$_GET['gamer_id'] = $_SESSION['user']['id'];
								$gamers_obj->free_first_level($_SESSION['user']['id'],$_GET['gamer_id'],$about_user['privilege']);
							}
						}
					echo '</div>';
				
					
					$j = 0;					
						while ($j != 3)
						{
							if (isset($first_level_mas[$j])){
								echo '<div class="three">';
								$second_level_mas = $gamers_obj->child($first_level_mas[$j]);
								for ($i=0;$i<3;$i++){
									if (isset($second_level_mas[$i]))
										$gamers_obj->second_level($second_level_mas[$i],$about_user['privilege']);
									else
									{
										if (isset($first_level_mas[$j]))
											$gamers_obj->free_second_level($_SESSION['user']['id'],$first_level_mas[$j],$about_user['privilege']);
									}
								}
								echo '</div>';
							}									
							$j++;
						}	
					
					}?>		
					
				</div>
				<?php endif; ?>
				
				<?php if (isset($_GET['action']) && ($_GET['action']=='cabinet')): ?>						
					<div class="cabinet_user">
						<div class="user_data">
							<span class="hello">Здравствуйте, <?php echo $about_user['login']?></span>							
							<?php 
								$image_id = $gamers_obj->select_image($_SESSION['user']['id']); 
								$image = $gamers_obj->image($image_id);

							?>		
							<div id="img_user">
								<img class="image" src="<?php echo $image; ?>"/>
								<a id="photo" href="#" title="Изменить фото">Изменить фото</a>
							</div>
						</div>
						<h3 class="page_title"> Ваши данные</h3>
						<div class="hr"></div>
						<form action="" method="post" class="about_user">
							<p><label for="id_upd">Идентификатор</label><input type="text" value="<?php echo $_SESSION['user']['id']; ?>" name="login_id" id="login_id" readonly="readonly" maxlength="255"/></p>
							<p><label for="login_upd">Логин</label><input type="text" value="<?php echo $about_user['login']; ?>" name="login_upd" id="login_upd" readonly="readonly" maxlength="255"/></p>
							<p><label for="email_upd">Email</label><input type="text" value="<?php echo $about_user['email']; ?>" name="email_upd" id="email_upd" readonly="readonly" maxlength="255"/></p>
							<div class="hr"></div>
							<p><label for="name_upd">Имя</label><input type="text" value="<?php echo $about_user['name']; ?>" name="name_upd" id="name_upd" maxlength="255"/></p>
							<p><label for="surname_upd">Фамилия</label><input type="text" value="<?php echo $about_user['surname']; ?>" name="surname_upd" id="surname_upd" maxlength="255"/></p>		
							<p><label for="phone_upd">Номер телефона</label><input type="text" value="<?php echo $about_user['phone']; ?>" name="phone_upd" id="phone_upd" maxlength="255"/></p>
							<p><label for="country_upd">Страна</label><select name="country_upd" id="country_upd"><option value="<?php echo $about_user['country']; ?>"><?php echo $core_obj->value_country($about_user['country']); ?></option><?php  echo $location_obj->getCountries();?></select></p>
							<p><label for="city_upd">Город</label><select name="city_upd" class="pro" id="city_upd"><?php echo $core_obj->value_city($about_user['country'],$about_user['city']); ?></select></p>
							<input type="button" class="red_but" value="Сохранить изменения" id="user-update"/>
							<input type="reset" value="Отменить изменения" id="clear_cabinet"/>		
						</form>			
					</div>	
				<?php endif; ?>	
				
				<?php if (isset($_GET['action']) && ($_GET['action']=='allgamers') && ($about_user['privilege'] == 3)): ?>
						<h3 class="page_title">Все участники</h3>
						<div class="hr"></div>
						<p class="textright new-user-link"><a href="profile.php?action=adduser" title="Добавить пользователя">Добавить пользователя</a></p>
						<?php echo $admin_obj->show_gamers(); ?>
						<div class="hr"></div>
						<p class="textright new-user-link"><a href="profile.php?action=adduser" title="Добавить пользователя">Добавить пользователя</a></p>
				<?php endif; ?>
				
				<?php if(isset($_GET['action']) && ($_GET['action']=='child') && (!isset($_GET['id_child']))): ?>
					<h3 class="page_title">Мои помощники</h3>
					<div class="hr"></div>
					<?php 
						$mas_layer_1 = array();
						$mas_layer_2 = array();
						$mas_layer_3 = array();
						$mas_layer_1 = $admin_obj->mas_1($_SESSION['user']['id']);
						
						$n = count($mas_layer_1);						 
						if (!empty($mas_layer_1)){
							$mas_layer_2 = $admin_obj->mas_2($mas_layer_1);
							$n = count($mas_layer_2);						 
							 for($i = 0; $i < $n; $i++){
								if( (isset($_GET['gamer_id'])) &&($_GET['gamer_id'] == $mas_layer_2[$i])){
									$f2 = false;
									break;
								}
							}
						}
						
						if (!empty($mas_layer_2)){
							$mas_layer_3 = $admin_obj->mas_2($mas_layer_2);
							$n = count($mas_layer_3);			
								for($i = 0; $i < $n; $i++){		
								  if( (isset($_GET['gamer_id'])) &&($_GET['gamer_id'] == $mas_layer_3[$i])){				  
									$f3 = false;
									break;
								}							
							}
						}
						
						
											
						echo $gamers_obj->layer_child3($mas_layer_1, $mas_layer_2, $mas_layer_3, $_SESSION['user']['id']);
					?>
				<?php endif; ?>
				<?php if (isset($_GET['action']) && ($_GET['action']=='child')&& (isset($_GET['id_child']))):?>
					<div class="cabinet_user">
						<h3 class="page_title">Данные о пользователе идентификатор = <?php echo $_GET['id_child']; ?></h3>
						<div class="hr"></div>
						<div class="user_update">
						<?php
							$res = $admin_obj->select_user($_GET['id_child']);
							$image = $gamers_obj->select_image($res['image']);
							/*if (!file_exists($image))
								$image = '../images/uploads/no-user-icon.png';*/
							if ($image != ""):?>
								
								<div id="img_user">
									<img class="image" src="<?php echo $users_obj->image($image); ?>"/>	
								</div>
							
							<?php endif; ?>				
							<form action="" method="post" class="about_user">
								<p><label>Логин</label><input type="text" value="<?php echo $res['login']; ?>" readonly="readonly" maxlength="255"/></p>
								<p><label>Имя</label><input type="text" value="<?php echo $res['name']; ?>" readonly="readonly" maxlength="255"/></p>
								<p><label>Фамилия</label><input type="text" value="<?php echo $res['surname']; ?>" readonly="readonly" maxlength="255"/></p>		
								<p><label>Номер телефона</label><input type="text" value="<?php echo $res['phone']; ?>" readonly="readonly" maxlength="255"/></p>
								<p><label>email</label><input type="text" value="<?php echo $res['email']; ?>" readonly="readonly" maxlength="255"/></p>
								<p><label>Страна</label><input type="text" value="<?php echo $core_obj->value_country($res['country'],$res['country']); ?>" readonly="readonly" maxlength="255"/></p>
								<p><label>Город</label><input type="text" value="<?php echo $core_obj->value_city_show($res['city']); ?>" readonly="readonly" maxlength="255"/></p>			
								<p><label for="payd">Уровень пройден</label><input type="checkbox" name="payd" id="payd" value="0" <?php  if($gamers_obj->is_payd($_GET['id_child'])):?>checked disabled<?php endif; ?> maxlength="255"/></p>
							</form>			
						</div>
					</div>
				<?php endif; ?>
				
				<?php if (isset($_GET['action']) && ($_GET['action']=='alluser') && ($about_user['privilege'] == 3)): ?>
						<h3 class="page_title">Все пользователи</h3>
						<div class="hr"></div>
						<p class="textright new-user-link"><a href="profile.php?action=adduser" title="Добавить пользователя">Добавить пользователя</a></p>
						<?php echo $admin_obj->show_users(); ?>
						<div class="hr"></div>
						<p class="textright new-user-link"><a href="profile.php?action=adduser" title="Добавить пользователя">Добавить пользователя</a></p>
				<?php endif; ?>
				
				<?php 
					if (isset($_GET['action']) && ($_GET['action']=='update_user')&&(isset($_GET['id_user'])) && ($about_user['privilege'] == 3)):?>
					<h3 class="page_title">Редактировать данные о пользователе</h3>
					<div class="hr"></div>
					<?php
						$res = $admin_obj->select_user($_GET['id_user']);
						$res_gamers = $gamers_obj->about_gamer($_GET['id_user']);
					?>	
					<?php
						if ($res['is_active']):?>
							<p class="page_title">Статус: Online</p>
						<?php else: 
							if (($res['last_visit'])!='')
								echo 'Последнее посещение в '.date("H:i:s, d.m.Y",$res['last_visit']);
							else
								echo 'Последнее посещение в ';
							$date = $res['last_visit'] - $res['visit'];
							echo '<p>Время пребыванья '.$core_obj->time_difference($date).'</p>';
						?>
						<p>Статус: Offline</p>
					<?php endif; ?>
					<p>Уровень <?php echo $res_gamers['layer']; ?></p>
					<p> Платеж пользователю Идентификатор=<?php echo $res_gamers['next_parent']; ?></p>
					
						<form action="" method="post" class="about_user">
							<p><label for="upd_id">Идентификатор</label><input type="text" value="<?php echo $res['id']; ?>" name="upd_id" id="upd_id" readonly="readonly" maxlength="255"/></p>
							<p><label for="upd_login">Логин</label><input type="text" value="<?php echo $res['login']; ?>" name="upd_login" id="upd_login" readonly="readonly" maxlength="255"/></p>
							<p><label for="upd_name">Имя</label><input type="text" value="<?php echo $res['name']; ?>" name="upd_name" id="upd_name" maxlength="255"/></p>
							<p><label for="upd_surname">Фамилия</label><input type="text" value="<?php echo $res['surname']; ?>" name="upd_surname" id="upd_surname" maxlength="255"/></p>		
							<p><label for="upd_phone">Номер телефона</label><input type="text" value="<?php echo $res['phone']; ?>" name="upd_phone" id="upd_phone" maxlength="255"/></p>
							<p><label for="upd_email">email</label><input type="text" value="<?php echo $res['email']; ?>" name="upd_email" id="upd_email" maxlength="255"/></p>
							<p><label for="upd_country">Страна</label><select name="upd_country" id="upd_country"><option selected value="<?php echo $res['country']; ?>"><?php echo $core_obj->value_country( $res['country']); ?></option><?php echo $location_obj->getCountries(); ?></select></p>
							<p><label for="upd_city">Город</label><select name="upd_city" class="pro" id="upd_city"><option value="<?php echo $res['city'];?>"><?php echo $core_obj->value_city($res['country'], $res['city']); ?></option></select></p>
							<p><label for="payd_admin">Уровень пройден</label><input type="checkbox" name="payd_admin" id="payd_admin" value="0" <?php  if($gamers_obj->is_payd($_GET['id_user'])):?>checked<?php endif; ?> maxlength="255"/></p>
							<p><input type="button" value="На уровень выше" id="<?php echo $res['id']; ?>" class="level_plus">
							<input type="button" value="На уровень ниже" id="<?php echo $res['id']; ?>" class="level_minus"></p>
							<input type="button" value="Сохранить изменения" id="upd_user">
						</form>	
					
				<?php endif; ?>
				
				<?php if (isset($_GET['action']) && ($_GET['action']=='adduser') && ($about_user['privilege'] == 3)):?>
					<h3 class="page_title">Добавить пользователя</h3>
					<div class="hr"></div>
						<form action="" method="get" class="about_user">
							<p><label for="login">Логин</label><input type="text" name="login" id="login" maxlength="255"/></p>
							<p><label for="password">Пароль</label><input type="password" name="password" id="password" maxlength="255"/></p>
							<p><label for="confirm">Подтверждение</label><input type="password" name="confirm" id="confirm" maxlength="255"/></p>		
							<p><label for="name">Имя</label><input type="text" name="name" id="name" maxlength="255"/></p>
							<p><label for="surname">Фамилия</label><input type="text" name="surname" id="surname" maxlength="255"/></p>		
							<p><label for="phone">Номер телефона</label><input type="text" name="phone" id="phone" maxlength="255"/></p>
							<p><label for="email">email</label><input type="text" name="email" id="email" maxlength="255"/></p>
							<p><label for="country">Страна</label><select name="country" id="country"><option value="0">Выберите страну...</option><?php echo $location_obj->getCountries(); ?></select></p>
							<p><label for="city">Город</label><select name="city" id="city"><option value="0">Выберете город...</option></select></p>
							<input type="button" value="Добавить пользователя" id="add_user">
						</form>					
				<?php endif; ?>
		
			<?php if (isset($_GET['action']) && ($_GET['action']=='allpage') && (!isset($_GET['id_page'])) && ($about_user['privilege'] == 3)):?>
				<h3 class="page_title">Все страницы</h3>
				<div class="hr"></div>
				<p class="textright new-user-link"><a href="profile.php?action=addpage" title="Добавить страницу">Добавить страницу</a></p>				
				<?php					
					if (isset($_POST['find_pages']))
						echo $admin_obj->find_pages($_POST['find_pages']);
					else
						echo($admin_obj->show_pages()); ?>
				<p class="textright new-user-link"><a href="profile.php?action=addpage" title="Добавить страницу">Добавить страницу</a></p>				
			<?php endif;?>
			
			<?php if (isset($_GET['action']) && ($_GET['action']=='update_page')&&(isset($_GET['id_page'])) && ($about_user['privilege'] == 3)):?>
				<?php $res0 = $admin_obj->select_pages((int)$_GET['id_page']); $res = $res0[0]; ?>
				<h3 class="page_title">Редактирование страницы <?php echo $res['title']; ?></h3>
				<div class="hr"></div>
				<form action="" method="get" class="data_page">
					<p><label for="title_page">Заголовок</label><input type="text" name="title_page" id="title_page" value="<?php echo $res['title']; ?>" maxlength="255"/></p>
					<p><textarea id="elm1" name="elm1" rows="15" cols="80" style="max-width: 600px" class="tinymce"><?php echo $res['content']; ?></textarea></p>
					<p><label for="in_menu">Отображать в меню</label><input type="checkbox" name="in_menu" id="in_menu" value="0" <?php if($res['in_menu']):?>checked<?php endif; ?> maxlength="255"/></p>
					<p><label for="seo_title">SEO Title</label><input type="text" name="seo_title" class="seo" id="seo_title" value="<?php echo $res['seo_title']; ?>" maxlength="255"/></p>
					<p><label for="seo_description">SEO Description</label><input type="text" name="seo_description" class="seo" id="seo_description" value="<?php echo $res['seo_description']; ?>" maxlength="255"/></p>
					<p><label for="seo_keywords">SEO Keywords</label><textarea class="seo" id="seo_keywords" name="seo_keywords">
						<?php echo $res['seo_keywords']; ?>
					</textarea></p>				
					<p><input type="button" value="Сохранить изменения" id="update_page"></p>
				</form>
			<?php endif; ?>
		
			<?php if (isset($_GET['action']) && ($_GET['action']=='addpage') && ($about_user['privilege'] == 3)):?>
				<h3 class="page_title">Добавить страницу</h3>
				<div class="hr"></div>
				<div class="profile">
				<form action="" method="get" class="data_page">
					<p><label for="title_page">Заголовок</label><input type="text" name="title_page" id="title_page"  maxlength="255"/></p>
					<p><textarea id="elm1" name="elm1" rows="15" cols="80" style="max-width: 600px" class="tinymce">							
					</textarea></p>
					<p><label for="in_menu">Отображать в главном меню</label><input type="checkbox" name="in_menu" id="in_menu" value="0" /></p>
					<p><label for="seo_title">SEO Title</label><input type="text" name="seo_title" class="seo" id="seo_title" value="" maxlength="255"/></p>
					<p><label for="seo_description">SEO Description</label><input type="text" name="seo_description" class="seo" id="seo_description" value="" maxlength="255"/></p>
					<p><label for="seo_keywords">SEO Keywords</label><textarea class="seo" id="seo_keywords" name="seo_keywords">
					</textarea></p>	
					<p><input type="button" value="Добавить" id="add_page"></p>
				</form>
				</div>
			<?php endif; ?>
			
			<?php
				if (isset($_GET['action'])&&($_GET['action']=='only_reg')&&(!isset($_GET['id_user'])) && ($about_user['privilege'] == 3)):?>
					<h3 class="page_title">Ждут распределения</h3>
					<div class="hr"></div>
					<?php echo $gamers_obj->only_reg();
				endif; 
			?>
			
			<?php if (isset($_GET['action'])&&($_GET['action']=='only_reg')&&(isset($_GET['id_user'])) && ($about_user['privilege'] == 3)) :?>
				<h3 class="page_title">Выбрать куратора</h3>
				<div class="hr"></div>
				<?php $res = $admin_obj->select_user($_GET['id_user']); ?>
				<div class="cabinet_user">
					<div class="user_update">
					<?php $res = $admin_obj->select_user($_GET['id_user']);
						$image = $users_obj->select_image($_GET['id_user']);
						if (!file_exists($image))
							$image = '../images/uploads/no-user-icon.png';
						if ($image):?>
							
							<div id="img_user">
								<img class="image" src="<?php echo $users_obj->image($image); ?>"/>	
							</div>
						
						<?php endif; ?>
						<form action="" method="post" class="about_user">
							<p><label>Идентификатор</label><input type="text" id="id_user" name="id_user" value="<?php echo $res['id']; ?>" readonly="readonly" maxlength="255"/></p>
							<p><label>Логин</label><input type="text" value="<?php echo $res['login']; ?>" readonly="readonly" maxlength="255"/></p>
							<p><label>Имя</label><input type="text" value="<?php echo $res['name']; ?>" readonly="readonly" maxlength="255"/></p>
							<p><label>Фамилия</label><input type="text" value="<?php echo $res['surname']; ?>" readonly="readonly" maxlength="255"/></p>		
							<p><label>Номер телефона</label><input type="text" value="<?php echo $res['phone']; ?>" readonly="readonly" maxlength="255"/></p>
							<p><label>email</label><input type="text" value="<?php echo $res['email']; ?>" readonly="readonly" maxlength="255"/></p>
							<p><label>Страна</label><input type="text" value="<?php echo $core_obj->value_country($res['country']); ?>" readonly="readonly" maxlength="255"/></p>
							<p><label>Город</label><input type="text" value="<?php echo $core_obj->value_city_show($res['city']); ?>" readonly="readonly" maxlength="255"/></p>
							<p><label for="id_parent">Идентификатор куратора</label><input type="text" name="id_parent" id="id_parent" value="" maxlength="255"/></p>
							<input type="button" value="Подтверждение" id="admin_add_parent">
						</form>
					</div>
			</div>
			<?php endif; ?>
			
			<?php 
				if (isset($_GET['action']) && ($_GET['action']=='message') && (!isset($_GET['id_mes']))):?> 
					<h3 class="page_title">Входящие сообщения</h3>
					<div class="hr"></div>
				<?php 
					echo $users_obj->show_no_read($_SESSION['user']['id']);
					endif; 
			?>
			
			<?php 
				if (isset($_GET['action']) && ($_GET['action']=='inbox') && (!isset($_GET['id_mes']))) :?>
					<h3 class="page_title">Входящие сообщения</h3>
					<div class="hr"></div>
				<?php
					echo $users_obj->show_inbox_message($_SESSION['user']['id']);
					endif;
			?>
		
			<?php if (isset($_GET['action']) && ($_GET['action']=='inbox') && (isset($_GET['id_mes']))) :?>
				<?php 
					$from = $users_obj->dataUser($_GET['from']);
					$to = $users_obj->dataUser($_GET['to']);
					$data_mes = $users_obj->data_message($_GET['id_mes']);
					if (($data_mes['toReaded'] == 0) && ($_GET['to'] == $_SESSION['user']['id']))
						$users_obj->toReaded($_GET['id_mes']); 
				?>			   
				<div class='r_message'>
					<h3 class="page_title">
						<?php if ($data_mes['theme'] == ''){ $data_mes['theme'] = 'Без темы'; } echo $data_mes['theme']; ?>
					</h3>
					<div class="hr nomarginbottom"></div>
					<div class="meta">
						<div class="floatleft">Дата: <?php echo date('d.m.Y H:i:s',strtotime($data_mes['date']));?></div>
						<div class="floatright">Отправитель:<?php echo $from['name'].' '.$from['surname']; echo ' &lt'.$from['email'].'&gt'; ?></div>
					</div>
					<input id="name_surname" type="hidden" value="<?php echo $from['name'].' '.$from['surname']; ?>"/>
					<div class="mail-body"><?php echo $data_mes['text']; ?></div>
					<div class="buttons">
						<a href="#" id="<?php echo $from['id']; ?>" class="send_message send_message_admin">Ответить</a>
					</div>
				</div>	
			<?php endif; ?>
			
			<?php 
				if (isset($_GET['action']) && ($_GET['action']=='outbox') && (!isset($_GET['id_mes']))) :?> 
					<h3 class="page_title">Исходящие сообщения</h3>
					<div class="hr"></div>
				<?php					
					echo $users_obj->show_outbox($_SESSION['user']['id']);
					endif;
			?>
		
			<?php 
				if (isset($_GET['action']) && ($_GET['action']=='outbox') && (isset($_GET['id_mes']))) :?>
					<?php 
						$from = $users_obj->dataUser($_GET['from']);
						$to = $users_obj->dataUser($_GET['to']);
						$data_mes = $users_obj->data_message($_GET['id_mes']);
						if (($data_mes['toReaded'] == 0) && ($_GET['to'] == $_SESSION['user']['id']))
							$users_obj->toReaded($_GET['id_mes']); 
					?>		   

					<div class='r_message'>
						<h3 class="page_title">
							<?php if ($data_mes['theme'] == ''){ $data_mes['theme'] = 'Без темы'; } echo $data_mes['theme']; ?>
						</h3>
						<div class="hr nomarginbottom"></div>
						<div class="meta">
							<div class="floatleft">Дата: <?php echo date('d.m.Y H:i:s',strtotime($data_mes['date']));?></div>
							<div class="floatright">Отправитель:<?php echo $from['name'].' '.$from['surname']; echo ' &lt'.$from['email'].'&gt'; ?></div>
						</div>
						<input id="name_surname" type="hidden" value="<?php echo $from['name'].' '.$from['surname']; ?>"/>
						<div class="mail-body"><?php echo $data_mes['text']; ?></div>
					</div>	

			<?php endif; ?>
		
			<?php if (isset($_GET['action']) && ($_GET['action']=='trash') && (!isset($_GET['id_mes']))) :?>
					<h3 class="page_title">Корзина сообщений</h3>
					<div class="hr"></div>
				<?php 
					echo $users_obj->show_trash($_SESSION['user']['id']); 
					endif; 
			?>
		
			<?php 
				if (isset($_GET['action']) && ($_GET['action']=='trash') && (isset($_GET['id_mes']))) :?>
					<?php
						$from = $users_obj->dataUser($_GET['from']);
						$to = $users_obj->dataUser($_GET['to']);
						$data_mes = $users_obj->data_message($_GET['id_mes']);
						if (($data_mes['toReaded'] == 0) && ($_GET['to'] == $_SESSION['user']['id']))
							$users_obj->toReaded($_GET['id_mes']); 
					?>
		   
				<div class='r_message'>
					<p>От кого: 
						<?php 
							echo $from['name'].' '.$from['surname'];
							echo ' &lt'.$from['email'].'&gt'; 
						?> 
					</p>
					<p>Кому: <?php echo ' &lt'. $to['email'].'&gt'; ?></p>	
					<p> <?php echo date('H:i:s, d.m.Y',strtotime($data_mes['date'])); ?></p>
					<p>Тема:
						<?php 
							if ($data_mes['theme'] == '')
								$data_mes['theme'] = 'Без темы';
							echo $data_mes['theme'];
						?>
					</p>
					<form action='' method='post'>
						<input type="hidden"  value="<?php echo $from['login']; ?>" name="from" id="from"/>
						<input type="hidden"  value="<?php echo $_GET['from']; ?>" name="id_to" id="id_to"/>
						<p><label for='text'>Текст</label></p><textarea id='text' name=text><?php echo $data_mes['text']; ?></textarea>
					</form>
				</div>		
				<?php elseif (isset($_GET['action']) && ($_GET['action']=='add_child') && ($about_user['privilege']!=3)) :?>		
					<div class = "reg">
						<form action="" method="get">
							<p><label for="login">Логин</label><input type="text" name="login" id="login" maxlength="255"/></p>
							<p><label for="name">Имя</label><input type="text" name="name" id="name" maxlength="255"/></p>
							<p><label for="surname">Фамилия</label><input type="text" name="surname" id="surname" maxlength="255"/></p>		
							<p><label for="phone">Номер телефона</label><input type="text" name="phone" id="phone" maxlength="255"/></p>
							<p><label for="email">email</label><input type="text" name="email" id="email" maxlength="255"/></p>
							<p><label for="country">Страна</label><select name="country" id="country"><option value="0">Выберите страну...</option><?php echo $location_obj->getCountries(); ?></select></p>
							<p><label for="city">Город</label><select name="city" id="city"><option value="0">Выберете город...</option></select></p>
							<input type="button" value="Добавить пользователя" id="add_other_user">
						</form>
					</div>
				<?php endif; ?>
				
				<?php 
					if (isset($_GET['action']) && ($_GET['action']=='add_parent') && ($gamers_obj->is_gamer($_SESSION['user']['id']) == false)) :?>
						<div class="user_add_parent">
							<p><label for="id">Идентификатор</label><input type="text" name="id" id="id" maxlength="255"/></p>
							<input type="button" value="Добавить куратора" id="add_parent">
						</div>				
				<? endif;?>
			</div>
			<aside>
				<div class="current-user">
					Идентификатор:
					<b><?php if (isset($_SESSION['user']['id'])) echo $_SESSION['user']['id'];?></b>
				</div>
				<?php if(isset($about_user['privilege']) && ($about_user['privilege'] == 3)):?>
				<nav>
					<ul>
						<li class="cabinet"><a href="profile.php?action=cabinet"><span>Кабинет</span></a>
							<ul>
								<li class="profile"><a href="profile.php?action=cabinet">Мой профиль</a></li>
								<li class="piramida"><a href="profile.php?action=pyramid">Моё дерево</a></li>
								<li class="subordinates"><a href="profile.php?action=allgamers">Все участники</a></li>
								<li class="subordinates"><a href="profile.php?action=child">Мои помощники</a></li>
								<li class="all-users"><a href="profile.php?action=alluser">Список пользователей</a></li>								
								<li class="new-users"><a href="profile.php?action=adduser">Добавить пользователя</a></li>
							</ul>
						</li>
						<li class="new-password"><a href="profile.php?action=new_password" id="set-new-password"><span>Новый пароль</span></a></li>
						<li class="all-pages"><a href="profile.php?action=allpage"><span>Все страницы</span></a></li>
						<li class="registered"><a href="profile.php?action=only_reg"><span>Ждут распределения</span></a></li>
						<li class="messages"><a href="profile.php?action=message"><span>Сообщения <?php $amount = $users_obj->amount_inbox($_SESSION['user']['id']); if( $amount != 0) echo $amount; ?></span></a>
							<ul>
								<li class="inbox"><a href="profile.php?action=inbox">Входящие <?php $amount = $users_obj->all_amount_inbox($_SESSION['user']['id']); if( $amount != 0) echo $amount; ?></a></li>
								<li class="outbox"><a href="profile.php?action=outbox">Исходящие <?php $amount = $users_obj->all_amount_outbox($_SESSION['user']['id']);if ($amount != 0) echo $amount; ?></a></li>
								<li class="bascket"><a href="profile.php?action=trash">Корзина <?php $amount = $users_obj->amount_trash($_SESSION['user']['id']); if ($amount != 0) echo $amount; ?></a></li>
							</ul>
						</li>
						<li class="logout"><a href="profile.php?action=exit"><span>Выход</span></a></li>
					</ul>
				</nav>
				<?php endif; ?>
								
				<?php if(isset($about_user['privilege'])&& ($about_user['privilege'] < 3)):?>
				<nav>
					<ul>
						<li class="cabinet"><a href="profile.php?action=cabinet"><span>Кабинет</span></a>
							<ul>
								<li class="profile"><a href="profile.php?action=cabinet">Мой профиль</a></li>
								<li class="piramida"><a href="profile.php?action=pyramid">Моё дерево</a></li>
								<li class="subordinates"><a href="profile.php?action=child">Мои помощники</a></li>
								<?php if ($_SESSION['user']['privilege'] == 0):?>
									<li class="new-users"><a href="profile.php?action=add_parent">Добавить куратора</a></li>
								<?php endif; ?>
							</ul>
						</li>
						<li class="new-password"><a href="profile.php?action=new_password" id="set-new-password"><span>Новый пароль</span></a></li>
						
						<li class="messages"><a href="profile.php?action=message"><span>Сообщения <?php $amount = $users_obj->amount_inbox($_SESSION['user']['id']); if( $amount != 0) echo $amount; ?></span></a>
							<ul>
								<li class="inbox"><a href="profile.php?action=inbox">Входящие <?php $amount = $users_obj->all_amount_inbox($_SESSION['user']['id']); if( $amount != 0) echo $amount; ?></a></li>
								<li class="outbox"><a href="profile.php?action=outbox">Исходящие <?php $amount = $users_obj->all_amount_outbox($_SESSION['user']['id']);if ($amount != 0) echo $amount; ?></a></li>
								<li class="bascket"><a href="profile.php?action=trash">Корзина <?php $amount = $users_obj->amount_trash($_SESSION['user']['id']); if ($amount != 0) echo $amount; ?></a></li>
								<li class="admin-msg"><a href="profile.php?action=complain" id="complain"><span>Написать Администратору</span></a></li>
							</ul>
						</li>
						<li class="logout"><a href="profile.php?action=exit"><span>Выход</span></a></li>
					</ul>
				</nav>
				<?php endif; ?>
			</aside>
		</div>
	</section>
	<footer>
		<div class="in">
			<span>&copy;2011-2013. <a href="../index.php" title="ЗОЛОТОЕ ВРЕМЯ">ЗОЛОТОЕ ВРЕМЯ. </a> Все права защищены.</span>
			<div class="counters">
				<a href="#">
					<img src="../images/footer/counter.jpg" alt=""/>
				</a>
			</div>
			<nav>
				<ul>
					<?php $menu = $admin_obj->in_menu();
						foreach($menu as $menuItem){
							echo '<li><a href="../page.php?idpage='.$menuItem['id'].'" title="'.$menuItem['title'].'">'.$menuItem['title'].'</a></li>';
						}
					?>
				</ul>
			</nav>
		</div>
	</footer>
</body>
</head>